//
//  XZ_QRCardInfoController.m
//  Project_Demo
//
//  Created by caoxiaozhu on 2018/7/21.
//  Copyright © 2018年 caoxiaozhu. All rights reserved.
//

#import "XZ_QRCardInfoController.h"
#import "XZ_infoView.h"
#import "XZ_CompanyPayView.h"
#import "XZ_InfomationController.h"
#import "UseRecordController.h"
#import "DrawBackAlertWindow.h"
#import "GetCardAlertWindow.h"
#import "ShowQrCodeVc.h"

@interface XZ_QRCardInfoController ()<infoViewDelagte,drawBackDelegate,getCardDelegate>

@property(nonatomic,strong)XZ_AnimationAlertView *animationView;
@property(nonatomic,strong)XZ_infoView *infoView;
@property(nonatomic,assign)BOOL successGetCard;
@property(nonatomic,strong)NSString *cardStr;
@end

@implementation XZ_QRCardInfoController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"123");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _cardStr = @"123123213123213123";
    [self setupUI];
}

#pragma mark - 创建UI
-(void)setupUI{
    _infoView = [[XZ_infoView alloc]init];
    _infoView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    _infoView.chooseTitleArr = @[@"充值",@"乘车记录",@"使用帮助",@"退卡申请"];
    _infoView.chooseImageArr = @[@"卡片详情3",@"卡片详情2",@"卡片详情1",@"卡片详情5"];
    _infoView.delegate = self;
    if (_successGetCard) {
        _infoView.isAlreadyGetCard = true;
        _infoView.cardStr =_cardStr;
        _infoView.amount = @"50.00";
    }else{
        _infoView.isAlreadyGetCard = false;
    }
    
    [self.view addSubview:_infoView];
}

#pragma mark - 卡信息列表选项
-(void)chooseWhichTag:(NSInteger)tableTag{
    NSLog(@"tag==>%ld",tableTag);

    if (tableTag ==0) {
        //充值
        XZ_CompanyPayView *payView = [XZ_CompanyPayView new];
        [self.navigationController pushViewController:payView animated:true];
    }else if (tableTag==2){
        //使用帮助
        XZ_InfomationController *infoVc = [XZ_InfomationController new];
        [self.navigationController pushViewController:infoVc animated:true];
    }else if (tableTag == 1){
        //乘车记录
        UseRecordController *useRecordVc = [UseRecordController new];
        [self.navigationController pushViewController:useRecordVc animated:true];
    }else if (tableTag == 3){
        //退卡
        [self drawBackCard];
    }
}

#pragma mark - 立即使用/立即领卡
-(void)immediatelyUseBtnAction:(NSString *)cardNo BtnTag:(NSInteger)btnTag{
    NSLog(@"立即使用==>%@",cardNo);
    
    if(btnTag == 1){
        NSLog(@"立即领卡");
        //显示弹窗
        [self showCustomerViewInWindowType:1];
        [self refreshUIWithSuccessGetCard:true];
    }else{
        
        NSLog(@"立即使用");
        //显示qrCode
        ShowQrCodeVc *qrVc = [[ShowQrCodeVc alloc]init];
        qrVc.cardStr = _cardStr;
        [self.navigationController pushViewController:qrVc animated:true];
    }
}

-(void)refreshUIWithSuccessGetCard:(BOOL)type{
    
        //移除infoView
        [_infoView removeFromSuperview];
        //领卡成功/销卡未领卡
        _successGetCard = type;
        //更新UI
        [self setupUI];
}

#pragma mark - 退卡弹窗
-(void)drawBackCard{
    
    [self showCustomerViewInWindowType:2];
}

#pragma mark - 残忍退卡
-(void)drawBackAction{
    NSLog(@"退卡");
    [_animationView hideWithDur:1];
    [self refreshUIWithSuccessGetCard:false];
}

#pragma mark - 关闭弹窗
-(void)closeAction{
    [_animationView hideWithDur:1];
}

#pragma mark - 立即使用
-(void)chargeAction:(NSString *)cardStr{
    NSLog(@"cardNo==>%@",cardStr);
}

#pragma mark - 弹窗方法
-(void)showCustomerViewInWindowType:(NSInteger)type{
    
    UIView *customView = [[UIView alloc]init];
    
    //领卡成功
    if (type == 1) {
        GetCardAlertWindow *getCardWindow = [[[NSBundle mainBundle]loadNibNamed:@"GetCardAlertWindow" owner:self options:nil]firstObject];
        getCardWindow.delegate = self;
        getCardWindow.frame = CGRectMake(0, 0, 300, 308);
        customView = getCardWindow;
    }else{
        //退卡申请
        DrawBackAlertWindow *drawBackWindow = [[[NSBundle mainBundle]loadNibNamed:@"DrawBackAlertWindow" owner:self options:nil]firstObject];
        drawBackWindow.delegate = self;
        drawBackWindow.frame = CGRectMake(0, 0, 300, 160);
        customView = drawBackWindow;
    }
    
    _animationView = [[XZ_AnimationAlertView alloc]initWithCustomerView:customView PopStyle:XZ_AnimationPopStyleShakeFromTop DismissStyle:XZ_AnimationDismissStyleDropToBottom PopDuration:1 DismissDuration:1 ClickBacToHide:true BackAlpha:0.5];
    [self.view addSubview:_animationView];
}

@end
